package com.hertz.alarm.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	public static final String Y_M_D = "yyyy-MM-dd";
	public static final String YMD_HM = "yyyy-MM-dd HH:mm";
	public static final String HM = "HH:mm";
	public static String timeFormat(long millsec,String format){
		Calendar 		calendar = Calendar.getInstance();
		if(millsec > 0 )
			calendar.setTimeInMillis(millsec);
		SimpleDateFormat  sdf = new SimpleDateFormat(format);
		return sdf.format(calendar.getTime());
	}
	public static long string2Time(String time,String format){
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		long result = 0;
		try {
			Date date = formatter.parse(time);
			result = date.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static long nextDay(){
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, 1);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE,0);
		c.set(Calendar.SECOND,0);
		return c.getTimeInMillis();
	}
	
	public static String today(String format){
		long curretn = System.currentTimeMillis();
		return timeFormat(curretn, format);
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
